//	ID : pallab81
// 	PROG : 10201
// 	LANG : C++
// 	2011-08-05-19.47.51 Friday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define read( X ) scanf("%d", &(X) )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )


string line_feed="";
int miles;
const int inf = (int)1023456789;
vector< int > pump;
vector< vector<int> > cando;
string line;
template< class T >
inline void wait(T seconds ) {
    T endwait;
    endwait = clock() + seconds * CLOCKS_PER_SEC;
    while( clock() < endwait ) {
        ;
    }
}
inline void split( string &line ) {
    int x(-1),y(-1);
    sscanf(line.c_str(),"%d %d",&x,&y);
    if( y==-1 ) {
        miles = x;
        pump.assign( miles+10 , -1);
    } else {
        pump[ x ] = y;
    }
}
inline void Read() {
    while( getline(cin,line) ) {
        if( LN(line) <1 )break;
        split( line );
    }
}
inline void has_pump(int mile) {
    cando[ mile ][ 0 ] = cando[ mile-1 ][ 1 ];

    for(int fuel = 1; fuel<= 200 ; ++fuel ) {
        int a = cando[ mile ][ fuel - 1 ] + pump[mile] ;
        int b = cando[ mile-1][ fuel+1 ];
        cando[ mile ][ fuel ] = min( a,b );
    }
}
inline void no_pump(int mile) {
    for( int fuel = 0; fuel<=200; ++fuel ) {
        cando[ mile ][ fuel ] = cando[ mile-1 ][ fuel+1 ];
    }
}
inline void Proc() {
    cando.assign( miles+10 , vector<int>(210,inf ) );
    for(int i=0; i<=100; ++i) {
        cando[0][i]=0;
    }
    for(int mile=1; mile<=miles; ++mile) {
        if( pump[ mile ]!=-1 ) {
            has_pump( mile );
        } else {
            no_pump(mile);
        }
    }

//    for(int fuel=0; fuel<=200; ++fuel ){
//        printf("mile %d , fuel %d = %d\n",miles,fuel, cando[miles][fuel]);
//        wait( (double).2 );
//    }

    printf("%s",line_feed.c_str());
    line_feed="\n";
    if( cando[miles][100]>=inf ) {
        printf("Impossible\n");
    } else {
        printf("%d\n",cando[miles][100]);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
#endif
    int cases;
    read(cases);
    scanf("\n");
    while(cases--) {
        Read();
        Proc();
    }
    return 0;
}


